﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;

namespace Send2Sharepoint.Forms
{
    public class DateTimeControl : InputControl
    {
        public DateTimeControl(XmlNode element) : base(element)
        {
            var attributeCollection = element.Attributes;
            string defaultValue = element.ChildNodes[1] != null ? element.ChildNodes[1].InnerText : DateTime.Now.ToString();
            var name = attributeCollection["Name"].Value;
            var format = attributeCollection["Format"].Value;
            Field = new DateTimePicker
            {
                Name = "controlDtPicker_" + name,
                Size = new Size(250, 22),
                Format = DateTimePickerFormat.Custom,
                CustomFormat = (format == "DateTime" ? "dd/MM/yy hh:mm:s" : "dd/MM/yyyy"),
                Value = DateTime.Parse(defaultValue)
            };
            
        }

    }
}